﻿using System;
using System.Collections;
using System.Collections.Generic;
//using System.Linq;
using System.Web;
using System.Data;
using CE.Database;
/// <summary>
/// Summary description for CarInsuranceRenewalDB
/// </summary>
/// 
namespace CE.CarInsurance
{
    public class CarInsuranceRenewalDB
    {
        public CarInsuranceRenewalDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CarInsuranceRenewal renew)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCarInsuranceRenewalInsertUpdateSingleItem";
            SortedList _sPara = new SortedList();
            #region Parameter
            _sPara.Add("@CarRenewalID", renew.CarRenewalID);
            _sPara.Add("@CECarID", renew.CarID);
            _sPara.Add("@PremiumID", renew.PremiumID);
            _sPara.Add("@ProviderCompanyID", renew.ProviderCompanyID);
            _sPara.Add("@CustomerId", renew.CustomerID);
            _sPara.Add("@RefCEUserID", renew.RefCEUserID);
            _sPara.Add("@OrderNo", renew.OrderNo);
            _sPara.Add("@LastYearPolicyNo", renew.LastYearPolicyNo);
            _sPara.Add("@VehicleNo", renew.VehicleNo);
            _sPara.Add("@Info1", renew.Info1);
            _sPara.Add("@Info2", renew.Info2);
            _sPara.Add("@Info3", renew.Info3);
            _sPara.Add("@Info4", renew.Info4);
            _sPara.Add("@Info5", renew.Info5);
            _sPara.Add("@Info6", renew.Info6);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);
            return _result;
        }

        public CarInsuranceRenewal GetItemByOrderNo(string OrderNo)
        {
            CarInsuranceRenewal _carinsurancerenew = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarInsuranceRenewalSelectSingleItemByOrderNo";

            SortedList _spara = new SortedList();
            _spara.Add("@OrderNo", OrderNo);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _carinsurancerenew = new CarInsuranceRenewal();
                    _carinsurancerenew = FillDataRecord(_dt, 0);
                }
            }
            return _carinsurancerenew;
        }

        private CarInsuranceRenewal FillDataRecord(DataTable myDataTable, int RowId)
        {
            CarInsuranceRenewal myCarInsuranceRenew = new CarInsuranceRenewal();
            myCarInsuranceRenew.CarRenewalID = Convert.ToInt64(myDataTable.Rows[RowId]["CarRenewalID"].ToString());
            myCarInsuranceRenew.PremiumID = Convert.ToInt64(myDataTable.Rows[RowId]["PremiumID"].ToString());
            myCarInsuranceRenew.CarID = Convert.ToInt64(myDataTable.Rows[RowId]["CECarID"].ToString());
            myCarInsuranceRenew.ProviderCompanyID = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCompanyID"].ToString());
            myCarInsuranceRenew.CustomerID = Convert.ToInt64(myDataTable.Rows[RowId]["CustomerID"].ToString());
            myCarInsuranceRenew.RefCEUserID = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserID"].ToString());
            myCarInsuranceRenew.OrderNo = myDataTable.Rows[RowId]["OrderNo"].ToString();
            myCarInsuranceRenew.LastYearPolicyNo = myDataTable.Rows[RowId]["LastYearPolicyNo"].ToString();
            myCarInsuranceRenew.VehicleNo = myDataTable.Rows[RowId]["VehicleNo"].ToString();
            myCarInsuranceRenew.Info1 = myDataTable.Rows[RowId]["Info1"].ToString();
            myCarInsuranceRenew.Info2 = myDataTable.Rows[RowId]["Info2"].ToString();
            myCarInsuranceRenew.Info3 = myDataTable.Rows[RowId]["Info3"].ToString();
            myCarInsuranceRenew.Info4 = myDataTable.Rows[RowId]["Info4"].ToString();
            myCarInsuranceRenew.Info5 = myDataTable.Rows[RowId]["Info5"].ToString();
            myCarInsuranceRenew.Info6 = myDataTable.Rows[RowId]["Info6"].ToString();
            return myCarInsuranceRenew;

        }
    }
}
